home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / UTILS / HSBASIC2.DMS / in.adf / HB2Examples1.3.Lha / Examples / TimerArithmetic / TimerArithmetic.bas < prev   
Encoding:
BASIC Source File  |  1994-04-14  |  2.5 KB  |  72 lines

  1. ''
  2. '' $Id: TimerArithmetic.bas,v 1.2 1994/03/16 15:09:16 alex Rel $
  3. ''
  4. '' Example of timer device arithmetic functions
  5. ''
  6. '' Derived from RKM example (c) Copyright 1992 Commodore-Amiga, Inc.
  7. ''
  8.  
  9. DEFINT A-Z
  10.  
  11. 'REM $INCLUDE Exec.bh
  12. 'REM $INCLUDE Timer.bh
  13.  
  14. LIBRARY OPEN "exec.library", LIBRARY_MINIMUM&
  15.  
  16. SUB main
  17.     STATIC tr&, time1&, time2&, time3&
  18.     STATIC result&
  19.  
  20.     ' Get some memory for our structures (needs to be MEMF_PUBLIC)
  21.     time1& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
  22.     time2& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
  23.     time3& = AllocMem&(timeval_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
  24.     tr& = AllocMem&(timerequest_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
  25.  
  26.     ' Make sure we got the memory
  27.     IF time1& AND time2& AND time3& AND tr& THEN
  28.         ' Set up values to test time arithmetic with.  In a real application these
  29.         ' values might be filled in via the GET_SYSTIME command of the timer device
  30.         POKEL time1& + tv_secs, 3 : POKEL time1& + tv_micro, 0    ' 3.0 seconds
  31.         POKEL time2& + tv_secs, 2 : POKEL time2& + tv_micro, 500000    ' 2.5 seconds
  32.         POKEL time3& + tv_secs, 1 : POKEL time3& + tv_micro, 900000    ' 1.9 seconds
  33.  
  34.         PRINT "Time1 is"; PEEKL(time1& + tv_secs); "."; PEEKL(time1& + tv_micro)
  35.         PRINT "Time2 is"; PEEKL(time2& + tv_secs); "."; PEEKL(time2& + tv_micro)
  36.         PRINT "Time3 is"; PEEKL(time3& + tv_secs); "."; PEEKL(time3& + tv_micro)
  37.         
  38.         ' Open the MICROHZ timer device
  39.         IF OpenDevice&(SADD("timer.device" + CHR$(0)), UNIT_MICROHZ&, tr&, 0) = 0 THEN
  40.             ' Set up to use the special time arithmetic functions
  41.             LIBRARY VARPTR "timer.device", PEEKL(tr& + tr_node + IORequestio_Device)
  42.  
  43.             ' Now that TimerBase is initialised, it is permissible to call
  44.             ' the time-comparison or time-arithmetic routines.  Result of
  45.             ' this example is -1 which means the first parameter has greater
  46.             ' time value than second parameter +1 means the second parameter
  47.             ' is bigger; 0 means equal
  48.  
  49.             result& = CmpTime&(time1&, time2&)
  50.             PRINT "Time1 and Time2 compare ="; result&
  51.  
  52.             ' Add time2 to time1, result in time1
  53.             AddTime time1&, time2&
  54.             PRINT "Time1 + Time2 ="; PEEKL(time1& + tv_secs); "."; PEEKL(time1& + tv_micro)
  55.  
  56.             ' Subtract time3 from time2, result in time2
  57.             SubTime time2&, time3&
  58.             PRINT "Time2 - Time3"; PEEKL(time2& + tv_secs); "."; PEEKL(time2& + tv_micro)
  59.  
  60.             LIBRARY VARPTR "timer.device", NULL&
  61.             CloseDevice tr&
  62.         END IF
  63.     END IF
  64.     IF time1& THEN FreeMem time1&, timeval_sizeof
  65.     IF time2& THEN FreeMem time2&, timeval_sizeof
  66.     IF time3& THEN FreeMem time3&, timeval_sizeof
  67.     IF tr& THEN FreeMem tr&, timerequest_sizeof
  68. END SUB
  69.  
  70. main
  71. END
  72.